<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="se" uri="http://zc.security/acl"%>
<div id="cc_products" class="easyui-layout" style="width:100%;height:100%;" fit="true">
	<div data-options="region:'north',title:'商品管理',split:true" style="height:110px;background-color:#e6edfd;">
    	<form action="" id="searchForm" name="searchForm">
    	<table class="screen">
			<tr>
				<td class="screen-n"><span>商品编码|名称|拼音</span></td>
				<td class="screen-n">
					<input type="text" id="search_productName" class="screen-input"  style="width:200px"  onkeydown="pms.kd13('initProducts')">
				</td>
				<td class="screen-n"><span>品牌</span></td>
				<td class="screen-n">
					<input type="text" id="s_brand" class="screen-input" style="width:150px"  onkeydown="pms.kd13('initProducts')">
				</td>
				<td class="screen-n"><span>厂家</span></td>
				<td class="screen-n">
					<input type="text" id="s_producingName" class="screen-input" style="width:150px" onkeydown="pms.kd13('initProducts')">
				</td>
				<td class="screen-n"><span>分类</span></td>
				<td class="screen-n">
					<input class="easyui-combotree" id="s_productTypeCode"   name="s_productTypeCode" data-options="url:'<c:url value="/product/showEmBproductTypeList.do"/>?viewType=comboTree',method:'post'" missingmessage="请选择商品的唯一分类">
				</td>
			</tr>
				<tr>
				<td class="screen-n"><span>审核状态</span></td>
				<td class="screen-n">
					<select id="s_status">
						<option value="">-全部-</option>
						<option value="10">-已审核-</option>
						<option value="-99">-未审核-</option>
					</select>
				</td>
				<td class="screen-n"><span>上架状态</span></td>
				<td class="screen-n">
					<select id="s_isSale">
						<option value="">-全部-</option>
						<option value="1">-销售中-</option>
						<option value="0">-已下架-</option>
					</select>
				</td>
				
				<td class="screen-n"><span>库存状态</span></td>
				<td class="screen-n">
					<select id="viewsHasStockNum">
						<option value="">-全部-</option>
						<option value="1">-只显示有库存-</option>
					</select>
				</td>
				<td class="screen-n">
					 <input type="checkbox" id="s_isIndex" />首页推荐 
					 <input type="checkbox" id="s_isCommend" />推荐
					 <input type="checkbox" id="s_isComment" />热评 
					 <input type="checkbox" id="s_isTop" />置顶 
					 <input type="checkbox" id="s_isScroll" />滚动
				</td>
				
				<td class="screen-n">
					<input type="button" class="button" value="查询" onclick="initProducts()">
					<input type="button" class="button" value="重置" onclick="pms.resetForm('searchForm')" >
					<input type="button" class="button" value="导出" onclick="loadExecl('initStoreOutCheckTableExcel')" >
				</td>
			</tr>
		</table>
		</form>
    </div>
    
    
    <div data-options="region:'center',split:true" style="width: 100%;height: 100%">
		<table id="tableGrid"></table>
	</div>
 
 
</div> 

<div id="toolbar" style="display: none;">
    <table>
		 <tr>
			<td>
			<!--
			    <se:hasPermissions actCode="ADD" >
			 	<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-note_add',plain:true" onclick="addProductWindow();">商品录入</a>
				</se:hasPermissions>  -->
				<se:hasPermissions actCode="DELETE" >
					<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-note_delete',plain:true" onclick="deleteProduct();">删除商品</a>
				</se:hasPermissions>
				 
			</td>
			<td>
			
			<se:hasPermissions actCode="MAINTAIN">
		        <a href="#" class="easyui-menubutton" data-options="menu:'#mm1',iconCls:'ext-icon-key',plain:true">批量首页</a>
		        <div id="mm1">
			    	<div data-options="iconCls:'icon-redo'" onclick="batchUpdateProduct('isIndex',1);">首页</div>
			        <div data-options="iconCls:'icon-undo'" onclick="batchUpdateProduct('isIndex',0);">取消</div>
			    </div>
			    
			    <a href="#" class="easyui-menubutton" data-options="menu:'#mm2',iconCls:'ext-icon-key',plain:true">批量推荐</a>
		        <div id="mm2">
			    	<div data-options="iconCls:'icon-redo'" onclick="batchUpdateProduct('isCommend',1);">推荐</div>
			        <div data-options="iconCls:'icon-undo'" onclick="batchUpdateProduct('isCommend',0);">取消</div>
			    </div>
			    <a href="#" class="easyui-menubutton" data-options="menu:'#mm3',iconCls:'ext-icon-key',plain:true">批量置顶</a>
		        <div id="mm3">
			    	<div data-options="iconCls:'icon-redo'" onclick="batchUpdateProduct('isTop',1);">置顶</div>
			        <div data-options="iconCls:'icon-undo'" onclick="batchUpdateProduct('isTop',0);">取消</div>
			    </div>
			    <a href="#" class="easyui-menubutton" data-options="menu:'#mm4',iconCls:'ext-icon-key',plain:true">批量滚动</a>
		        <div id="mm4">
			    	<div data-options="iconCls:'icon-redo'" onclick="batchUpdateProduct('isScroll',1);">滚动</div>
			        <div data-options="iconCls:'icon-undo'" onclick="batchUpdateProduct('isScroll',0);">取消</div>
			    </div>
			    <a href="#" class="easyui-menubutton" data-options="menu:'#mm5',iconCls:'ext-icon-key',plain:true">批量热评</a>
		        <div id="mm5">
			    	<div data-options="iconCls:'icon-redo'" onclick="batchUpdateProduct('isComment',1);">热评</div>
			        <div data-options="iconCls:'icon-undo'" onclick="batchUpdateProduct('isComment',0);">取消</div>
			    </div>
			    <a href="#" class="easyui-menubutton" data-options="menu:'#mm6',iconCls:'ext-icon-key',plain:true">批量上下架</a>
		        
		        <div id="mm6">
			    	<div data-options="iconCls:'icon-redo'" onclick="batchUpdateProduct('isSale',1);">审核上架</div>
			        <div data-options="iconCls:'icon-undo'" onclick="batchUpdateProduct('isSale',0);">审核下架</div>
			    </div>
			  </se:hasPermissions> 
			</td>
		</tr>
	</table>
</div>
<script>

var productsTable;
$(function(){
	initProducts();
});
function getParams(){
	var queryParamss = {
			"searchWhere":$('#search_productName').val(),
			"brand":$("#s_brand").val(),
			"producingName":$("#s_producingName").val(),
			"productTypeCode":$("#s_productTypeCode").val(),
			"viewsHasStockNum":$("#viewsHasStockNum").val(),
			"isSale":$("#s_isSale").val(),
			"isIndex":$("#s_isIndex").is(':checked')?'1':'',
			"isCommend":$("#s_isCommend").is(':checked')?'1':'',
			"isTop":$("#s_isTop").is(':checked')?'1':'',
			"isComment":$("#s_isComment").is(':checked')?'1':'',
			"isScroll":$("#s_isScroll").is(':checked')?'1':'',
			"approveStatus":$("#s_status").val(),
			"isSale":$("#s_isSale").val(),
			"orderByType":"STOCK"
	    };
	
	return queryParamss;
}
 
 
function initProducts(){
	productsTable = $('#tableGrid').pDataGrid({
		toolbar:'#toolbar',
		 columns:[[
				  {field:'ck',checkbox:true,rowspan:2},
		          {field:'action',title:'操作',width:150,align:'center',rowspan:2,formatter:function(value,row){
			          var str='';
			          <se:hasPermissions actCode="UPDATE">
			          str+='<img class="iconImg ext-icon-application_edit" title="商品详情" onclick="openProductAddOrSaveWindow(\''+row.productCode+'\');"/>&nbsp;';
					  str+='<img class="iconImg ext-icon-image_add" title="商品图片管理" onclick="openProductPictureWindow(\''+row.productCode+'\');"/>&nbsp;';
			          str+='<img class="iconImg ext-icon-folder_page" title="商品资质文件管理" onclick="openProductBatchWindow(\''+row.productCode+'\');"/>&nbsp;';
				      str+='<img class="iconImg ext-icon-book_edit" title="商品说明书" onclick="openProductIntrductionWindow(\''+row.productCode+'\');"/>&nbsp;';
				      </se:hasPermissions>
				      <se:hasPermissions actCode="APPROVE">
				      str+='<img class="iconImg ext-icon-shield" title="审核操作" onclick="openProductUpdateWindow(\''+row.productCode+'\');"/>&nbsp;';
				      </se:hasPermissions>
				      return str;
		          }},
	              {field:'productCode',title:'商品编号',align:'center',rowspan:2,sortable:true},
	              {field:'productName',title:'商品名称',align:'center',rowspan:2,width:180,formatter:function(value,row){
						if(row.smallPic!="/images/noPic.jpg"){
							return row.productName+'&nbsp;<a href="'+contentPath+row.bigPic+'"   target="_blank"><img src="'+contentPath+'/images/selectimg.gif"   /></a>';
						}else{
							return row.productName;
						}
		          }},
	              {field:'spell',title:'拼音码',align:'center',rowspan:2},
	              {field:'productSpec',title:'规格',align:'center',rowspan:2,width:100},
	              {field:'packingUnit',title:'包装',align:'center',rowspan:2},
	              {field:'stockNum',title:'库存',align:'center',rowspan:2,styler:function(){return 'background-color:#ffee00;color:red;';}},
	              {field:'producingName',title:'生产厂家',align:'center',rowspan:2,width:200},
	              {field:'approveStatus',title:'审核状态',align:'center',width:60,rowspan:2,formatter:function(value,row){
					  if(value==0){
						return '×';
					  }else if(value==10){
						return '√';
					  }
					  else if(value==-10){
							return '<a href="#" title="查看原因">审核未通过</a>';
					  }
		          }},
		          {field:'isSale',title:'上架状态',align:'center',width:60,rowspan:2,formatter:function(value,row){
					  if(value==1){
						return '√';
					  }else {
						return '×';
					  }
					  
		          }},
	              {title:'价格',align:'center',colspan:7},
	              {field:'authorizeNumber',title:'批准文号',align:'center',rowspan:2,width:150},
	              {field:'productTypeName',title:'分类',align:'center',rowspan:2,width:100},
	              {field:'brand',title:'品牌',align:'center',rowspan:2,width:100},
	              {title:'额外属性',align:'center',colspan:5},
	              {field:'approveDate',title:'审核时间',align:'center',rowspan:2,width:80,formatter:function(value,row){
	            	  	if(value.length>10){
	            	  		return value.substring(0,10);
	            	  	}else{
	            	  		return value;
	            	  	}
						
		           }}
	          ],[
				  {field:'salePrice',title:'会员价',align:'center'},
				  {field:'controlSalePrice', title:'控销价',width:70,align:'center'},
				  {field:'shopPrice',title:'门店价',align:'center'},
				  {field:'cashPrice',title:'现金价',align:'center'},
				  {field:'middlePackPrice',title:'中包价',align:'center'},
				  {field:'fullSalePrice',title:'整件价',align:'center'},
				  {field:'retailPrice',title:'建议零售价',align:'center'},
				  {field:'isIndex',title:'首页',align:'center',formatter:function(value,row){
						if(row.isIndex==1) return '√';
						else return '×';
				  }},
				  {field:'isCommend',title:'推荐',align:'center',formatter:function(value,row){
						if(row.isCommend==1) return '√';
						else return '×';
				  }},
				  {field:'isTop',title:'置顶',align:'center',formatter:function(value,row){
						if(row.isTop==1) return '√';
						else return '×';
				  }},
				  {field:'isScroll',title:'滚动',align:'center',formatter:function(value,row){
						if(row.isScroll==1) return '√';
						else return '×';
				  }},
				  {field:'isComment',title:'热评',align:'center',formatter:function(value,row){
						if(row.isComment==1) return '√';
						else return '×';
				  }}
				  ]
			  ],
		    url:'<c:url value="/product/searchPageProduct.do"/>',  
		    pagination:true,
		    pageSize:10,
		    nowrap: false,
            striped: true,
            singleSelect: false,
            remoteSort: true,
            fitColumns: false,
            queryParams:getParams(),
		    completeCallback:function(data){
				if(data.code == "100"){
					alertError(data.result);
				} 
			}
		    ,
			onDblClickRow:function(index,row){
				<se:hasPermissions actCode="APPROVE">
				openProductUpdateWindow(row.productCode);
				</se:hasPermissions>
				
			},
			onLoadSuccess : function(data) {
				var panel = $(this).datagrid('getPanel');
				var tr = panel.find('div.datagrid-body tr');
				tr.each(function() {
					var td = $(this).children('td[field="productName"]');
					td.children("div").css({
						"text-align" : "left"
					});
				});
			}
	}); 
}



function openProductUpdateWindow(code){
	var params = {"productCode":code}
	$.pmsDialog({
		id:"w_product_tabs",
		title:'修改商品',
		isParent:true,
		method:'post',
		params:params,
		href:'<c:url value="/views/jsp/product/product_tabs.jsp"/>',
		width:1200
	});
}
function deleteProduct(code,i){
	var row = $('#tableGrid').datagrid('getSelections');
	if(row.length==0){
		alertWarning("您未选择任何商品!");
		return;
	}
	var param = new Object();
	for(var i=0;i<row.length;i++){
		param['list['+i+'].productCode']=row[i].productCode;
	}
	if(confirm("确定删除选择的商品?")){
		$.pmsAjax({
			url:'<c:url value="/product/deleteEmBProduct.do"/>',
			data:param,
			success:function(data){
				if(data.code=="200"){
					alertShow("删除成功");
				}else{
					alertError(data.result);
				}
			}
		});
	}
}
function addProductWindow(){
	var params = {};
	$.pmsDialog({
		id:"w_product_save_add",
		title:'商品录入',
		method:'post',
		href:'<c:url value="/views/jsp/product/product_save_update_s.jsp"/>',
		width:1100,
		params:params,
		isIf:'true'
		
	});
}

function openProductAddOrSaveWindow(productCode){
	var params = {"productCode":productCode};
	$.pmsDialog({
		id:"w_product_save_add",
		title:'商品详情',
		method:'post',
		href:'<c:url value="/views/jsp/product/product_save_update_s.jsp"/>',
		width:1100,
		params:params,
		isIf:'true'
		
	});
}

function openProductPictureWindow(productCode){
	var params = {"productCode":productCode};
	$.pmsDialog({
		id:"openProductPictureWindow",
		title:'商品图片管理',
		method:'post',
		href:'<c:url value="/views/jsp/product/product_pic_s.jsp"/>',
		width:1100,
		params:params,
		isIf:'true'
	});
}
function openProductIntrductionWindow(productCode){
	var params = {"productCode":productCode};
	$.pmsDialog({
		id:"openProductIntrductionWindow",
		title:'商品说明书管理',
		method:'post',
		href:'<c:url value="/views/jsp/product/product_instruction_s.jsp"/>',
		width:1200,
		params:params,
		isIf:'true'
	});
}
function openProductBatchWindow(productCode){
	var params = {"productCode":productCode};
	$.pmsDialog({
		id:"openProductBatchWindow",
		title:'商品资质文件管理',
		method:'post',
		href:'<c:url value="/views/jsp/product/product_qualification_s.jsp"/>',
		width:1100,
		params:params,
		isIf:'true'
	});
}

//批量修改商品
function  batchUpdateProduct(type,status){
	
	var row = $('#tableGrid').datagrid('getSelections');
	if(row.length==0){
		alertWarning("您未选择任何商品!");
		return;
	}
	var param = new Object();
	for(var i=0;i<row.length;i++){
		param['list['+i+'].productCode']=row[i].productCode;
		param['list['+i+'].'+type]=status;
	}
	$.pmsAjax({
		url:'<c:url value="/product/batchUpdateEmBProduct.do"/>',
		data:param,
		success:function(data){
			if(data.code=="200"){
				alertShow("批量操作成功");
			}else{
				alertError(data.result);
			}
		}
	});
}

function initStoreOutCheckTableExcel(){
	loadExcelCallBack('<c:url value="/product/searchPageProductExcel.do"/>',getParams());
}

</script>
